﻿using System;
using System.Drawing;

namespace Blitzcrank
{
    public static class PixelColor
    {
        public static Color GetPixelColorByImage(int x, int y)
        {
            using (var bitmap = new Bitmap(1, 1))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    graphics.CopyFromScreen(new Point(x, y), new Point(0, 0), new Size(5, 5));
                }
                return bitmap.GetPixel(0, 0);
            }
        }

        public static Color GetPixelColorByDevice(IntPtr hwnd, int x, int y)
        {
            uint pixel = Win32.GetPixel(hwnd, x, y);
            //Win32.ReleaseDC(IntPtr.Zero, hwnd);
            Color color = Color.FromArgb((int)(pixel & 0x000000FF),
                         (int)(pixel & 0x0000FF00) >> 8,
                         (int)(pixel & 0x00FF0000) >> 16);
            return color;
        }

        public static Bitmap CaptureBoard(Point upperLeft)
        {
            // create the new bitmap that holds the image of the control
            Bitmap bitmap = new Bitmap(320, 320);

            // copy controls image data to the bitmaps graphics device
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.CopyFromScreen(upperLeft, Point.Empty, new Size(320, 320));
            }

            return bitmap;
        }
    }
}
